import 'package:flutter/cupertino.dart';
import 'package:good_good_study/common/index.dart';
import 'package:good_good_study/entity/user_login_entity.dart' as Login;

class AppProvider extends ChangeNotifier {
  Login.Data userLoginData;

  static const String USER_LOGIN_ENTITY_KEY = "_USERLOGINENTITYKEY";

  Future<bool> setUserLoginData(Login.UserLoginEntity entity) async {
    await SPUtil.getInstance();
    userLoginData = entity.data;
    notifyListeners();
    return SPUtil.putObject(USER_LOGIN_ENTITY_KEY, userLoginData);
  }

  initUserLoginData() async {
    await SPUtil.getInstance();
    SPUtil.getObj(USER_LOGIN_ENTITY_KEY, (map) {
      userLoginData = Login.UserLoginEntity.fromJson(map).data;
    }, defValue: null);
    notifyListeners();
  }

  logOut() async {
    userLoginData = null;
    SPUtil.remove(USER_LOGIN_ENTITY_KEY);
    notifyListeners();
  }
}
